package com.nononsenseapps.feeder.util

import android.content.Context
import com.nononsenseapps.feeder.db.entity.FEED_ITEM_RULE_ACTION
import com.nononsenseapps.feeder.db.entity.FEED_ITEM_RULE_SOURCE
import com.nononsenseapps.feeder.db.entity.Feed
import com.nononsenseapps.feeder.db.entity.FeedRule
import com.nononsenseapps.feeder.db.room.*
import com.nononsenseapps.feeder.ui.R
import java.net.URL

object FeedExtensions {

    fun FEED_ALL(context: Context): Feed =
            Feed(
                ID_ALL_FEEDS,
                title = context.getString(R.string.all_feeds),
                customTitle = context.getString(R.string.all_feeds),
                url = URL("http://localhost/ALL_FEED_ID")
        )

    val systemFeedDictionary by lazy {
        mapOf(
            FAVORITE_FEED_ID to R.string.title_activity_favorite,
            MEMO_FEED_ID to R.string.feed_memo,
            RULE_FEED_ID to R.string.title_system_feed_rule,
            HOT_FEED_ID to R.string.title_system_feed_hot,
            STORE_FEED_ID to R.string.title_system_feed_store,
            BACKUP_FEED_ID to R.string.feed_backup,
            RECYCLE_FEED_ID to R.string.title_system_feed_recycle
        )
    }

    val feedRuleActionDictionary by lazy {
        mapOf<Int,Int>(
            FEED_ITEM_RULE_ACTION.MOVE_FEED to R.string.feed_rule_action_move_feed,
            FEED_ITEM_RULE_ACTION.REPLACE to R.string.feed_rule_action_replace,
            FEED_ITEM_RULE_ACTION.MARK_READ to R.string.feed_rule_action_mark_read,
            FEED_ITEM_RULE_ACTION.SCRIPT to R.string.feed_rule_action_script
        )
    }

    val feedRuleSourceDictionary by lazy {
        mapOf(
            FEED_ITEM_RULE_SOURCE.TITLE to R.string.feed_item_title,
            FEED_ITEM_RULE_SOURCE.IMAGE_URL to R.string.feed_item_image_url,
            FEED_ITEM_RULE_SOURCE.DESCRIPTION to R.string.feed_item_description,
            FEED_ITEM_RULE_SOURCE.ENCLOSURE_LINK to R.string.feed_item_enclosure_link,
            FEED_ITEM_RULE_SOURCE.AUTHOR to R.string.feed_item_author,
            FEED_ITEM_RULE_SOURCE.LINK to R.string.feed_item_link,
            FEED_ITEM_RULE_SOURCE.ITEM_TAGS to R.string.feed_item_tag
        )
    }

    fun getRuleStyleString(context: Context,rule: FeedRule):String{
        val str=when(rule.actionType){
            FEED_ITEM_RULE_ACTION.MOVE_FEED -> {
                var temp=context.getString(R.string.feed_rule_action_move_feed)
                systemFeedDictionary[rule.actionFeedId]?.let {
                            temp= temp+":" +  context.getString(it)
                        }
                temp
            }
            FEED_ITEM_RULE_ACTION.REPLACE ->context.getString(R.string.feed_rule_action_replace)
            FEED_ITEM_RULE_ACTION.MARK_READ -> context.getString(R.string.feed_rule_action_mark_read)
            FEED_ITEM_RULE_ACTION.SCRIPT -> context.getString(R.string.feed_rule_action_script)
            else ->""
        }

        return str
    }
}